home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / ghost / gs403src_png.lha / gs4.03 / libpng / pngerror.c < prev    next >
C/C++ Source or Header  |  1996-06-05  |  4KB  |  112 lines

  1.  
  2. /* pngerror.c - stub functions for i/o and memory allocation
  3.  
  4.    libpng 1.0 beta 3 - version 0.89
  5.    For conditions of distribution and use, see copyright notice in png.h
  6.    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  7.    May 25, 1996
  8.  
  9.    This file provides a location for all error handling.  Users which
  10.    need special error handling are expected to write replacement functions
  11.    and use png_set_error_fn() to use those functions.  See the instructions
  12.    at each function. */
  13.  
  14. #define PNG_INTERNAL
  15. #include "png.h"
  16.  
  17. static void png_default_error PNGARG((png_structp png_ptr,
  18.                                       png_const_charp message));
  19. static void png_default_warning PNGARG((png_structp png_ptr,
  20.                                         png_const_charp message));
  21.  
  22. /* This function is called whenever there is a fatal error.  This function
  23.    should not be changed.  If there is a need to handle errors differently,
  24.    you should supply a replacement error function and use png_set_error_fn()
  25.    to replace the error function at run-time. */
  26. void
  27. png_error(png_structp png_ptr, png_const_charp message)
  28. {
  29.    if (png_ptr->error_fn)
  30.       (*(png_ptr->error_fn))(png_ptr, message);
  31.  
  32.    /* if the following returns or doesn't exist, use the default function,
  33.       which will not return */
  34.    png_default_error(png_ptr, message);
  35. }
  36.  
  37. /* This function is called whenever there is a non-fatal error.  This function
  38.    should not be changed.  If there is a need to handle warnings differently,
  39.    you should supply a replacement warning function and use
  40.    png_set_error_fn() to replace the warning function at run-time. */
  41. void
  42. png_warning(png_structp png_ptr, png_const_charp message)
  43. {
  44.    if (png_ptr->warning_fn)
  45.       (*(png_ptr->warning_fn))(png_ptr, message);
  46.    else
  47.       png_default_warning(png_ptr, message);
  48. }
  49.  
  50. /* This is the default error handling function.  Note that replacements for
  51.    this function MUST NOT RETURN, or the program will likely crash.  This
  52.    function is used by default, or if the program supplies NULL for the
  53.    error function pointer in png_set_error_fn(). */
  54. static void
  55. png_default_error(png_structp png_ptr, png_const_charp message)
  56. {
  57. #ifndef PNG_NO_STDIO
  58.    fprintf(stderr, "libpng error: %s\n", message);
  59. #endif
  60.  
  61. #ifdef USE_FAR_KEYWORD
  62.    {
  63.       jmp_buf jmpbuf;
  64.       png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
  65.       longjmp(jmpbuf, 1);
  66.    }
  67. #else
  68.    longjmp(png_ptr->jmpbuf, 1);
  69. #endif
  70. }
  71.  
  72. /* This function is called when there is a warning, but the library thinks
  73.    it can continue anyway.  Replacement functions don't have to do anything
  74.    here if you don't want to.  In the default configuration, png_ptr is
  75.    not used, but it is passed in case it may be useful. */
  76. static void
  77. png_default_warning(png_structp png_ptr, png_const_charp message)
  78. {
  79.    if (!png_ptr)
  80.       return;
  81.  
  82. #ifndef PNG_NO_STDIO
  83.    fprintf(stderr, "libpng warning: %s\n", message);
  84. #endif
  85. }
  86.  
  87. /* This function is called when the application wants to use another method
  88.    of handling errors and warnings.  Note that the error function MUST NOT
  89.    return to the calling routine or serious problems will occur.  The return
  90.    method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) */
  91. void
  92. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  93.    png_error_ptr error_fn, png_error_ptr warning_fn)
  94. {
  95.    png_ptr->error_ptr = error_ptr;
  96.    png_ptr->error_fn = error_fn;
  97.    png_ptr->warning_fn = warning_fn;
  98. }
  99.  
  100.  
  101. /* This function returns a pointer to the error_ptr associated with the user
  102.    functions.  The application should free any memory associated with this
  103.    pointer before png_write_destroy and png_read_destroy are called. */
  104. png_voidp
  105. png_get_error_ptr(png_structp png_ptr)
  106. {
  107.    return png_ptr->error_ptr;
  108. }
  109.  
  110.  
  111.  
  112.